package com.xiaomoyu.pz;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

/**
 * 登录后获取用户信息
 * 相关解析HTMl的操作不是固定的
 * 需要结合自己的需求来操作
 * 此处仅作为演示。
 */
public class GetUserInfo {

    public static void main(String[] args) {

        CloseableHttpClient httpClient = HttpClients.createDefault();

        try {
            HttpGet httpGet = new HttpGet("http://qzjw.peizheng.edu.cn/jsxsd/framework/xsMain_new.jsp?t1=1");
            //增加头信息
            //注意此处需要修改为正确的JSESSIONID 和 BIGipServerpool_qzjw
            httpGet.addHeader("Cookie","JSESSIONID=; BIGipServerpool_qzjw=");
            httpGet.addHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36");
            httpGet.addHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
            httpGet.addHeader("Connection","keep-alive");

            //执行
            CloseableHttpResponse response = httpClient.execute(httpGet);
            String html = EntityUtils.toString(response.getEntity(), "utf8");
            System.out.println("结果："+html);
            //解析html
            Document parse = Jsoup.parse(html);
            Elements select = parse.select("div.middletopttxlr");
            Elements select1 = select.select("div.middletopdwxxcont");
            String text = select1.text();
            String[] s = text.split(" ");
            String name = s[1];//姓名
            String studentId = s[2];//学号
            String  department = s[3];//院系
            String  major = s[4];//专业
            String  stClass = s[5];//班级


            System.out.println(name+","+studentId+","+department+","+major+","+stClass);

        }catch (Exception e){

        }

    }
}
